class CartController < ApplicationController
  respond_to :js
  
  def add
    cart_item = CartItem.new(params[:id], 1)
    if session['cart'].include?(cart_item)
      existing_cart_item = session['cart'].find { |obj| cart_item == obj }
      existing_cart_item.increase
    else
      session['cart'] << cart_item
    end    
  end
  
  def remove
    cart_item = CartItem.new(params[:id], 0)
    session['cart'].delete(cart_item)
  end
  
  def empty
    session['cart'].clear
  end
end
